<template>
	<view class="baseForm">
		<view class="flex" style="min-height: 12vh">
			<u--form labelPosition="left" :model="umodel" ref="uForm" labelWidth="160rpx" errorType="toast">
				<u-form-item label="标签条码:" :labelWidth="'160rpx'">
					<scan-bar ref="scanBarRef1" placeholder="请扫描或输入标签条码" class="scan-bar" @code-scanned="barcodeParsing"></scan-bar>
				</u-form-item>
				<u-form-item label="仓位:" :labelWidth="'160rpx'">
					<scan-bar ref="scanBarRef2" placeholder="请扫描或输入仓位" class="scan-bar" @code-scanned="scanBin"></scan-bar>
					<u-button type="primary" text="选择" @click="binScan" style="width: 50px; height: 30px; margin-left: 5px"></u-button>
				</u-form-item>
				<!-- 				<u-form-item label="仓位名:" :labelWidth="'160rpx'">					
					<u-input
						:disabled="true"
						v-model="umodel.binName"
						placeholder="显示仓位名"
						disabled
						height="45px"></u-input>
				</u-form-item> -->
				<u-form-item label="RFID:" :labelWidth="'160rpx'" v-if="umodel.isRfid && umodel.isRfid == 1">
					<scan-bar ref="scanBarRef3" placeholder="请扫描或输入RFID" class="scan-bar" @code-scanned="scanRFID" v-model="umodel.rfid"></scan-bar>
				</u-form-item>
				<!-- <u-form-item label="物料号:" prop="remarks" :labelWidth="'160rpx'" style="height: 36px;padding: 5px 0;">
					<u-input
						:disabled="true"
						v-model="umodel.materialCode"
						placeholder="显示物料号"
						disabled
						height="45px"></u-input>
				</u-form-item>
				<u-form-item label="批次:" prop="remarks" :labelWidth="'160rpx'" style="height: 36px;padding: 5px 0;">
					<u-input
						:disabled="true"
						v-model="umodel.stockBatch"
						placeholder="显示批次"
						disabled
						height="45px"></u-input>
				</u-form-item>
				<u-form-item label="数量:" prop="remarks" :labelWidth="'160rpx'" style="height: 36px;padding: 5px 0;">
					<u-input
						:disabled="true"
						v-model="umodel.quantity"
						placeholder="显示数量"
						disabled
						height="45px"></u-input>
				</u-form-item> -->
			</u--form>
		</view>
		<u-line v-if="umodelList.length>0"></u-line>
		<view class="flex mt-8" style="min-height: 3vh" v-if="umodelList.length>0">
			<u-button text="返回" class="submit_btn1" @click="cancelBtn"></u-button>
			<u-button
				type="primary"
				:disabled="postLoading || !umodel.binId || !umodelList || umodelList.length == 0"
				:loading="postLoading"
				text="入库"
				@click="submit"
				class="search-btn u-m-l-20"
			></u-button>
		</view>
		<view class="flex mt-8" style="min-height: 3vh" v-if="umodelList.length>0">
			<u-button
				type="primary"
				:disabled="postLoading || !umodel.binId || !umodelList || umodelList.length == 0"
				:loading="postLoading"
				text="入库并继续"
				@click="submit2"
				class="search-btn u-m-l-20"
			></u-button>
		</view>
		<u-line></u-line>
		<!-- 列表部分 -->
		<view style="margin-top: 5px; overflow: auto">
			<view v-show="!umodelList.length" class="flex justify-center font-16" style="margin: 0px 0 0px 0">
				<u-empty mode="list"></u-empty>
			</view>
			<view v-if="umodelList.length">
				<u-list ref="tableScroll" @scrolltolower="scrolltolower" class="list" :pagingEnabled="false" :scrollable="false" height="auto">
					<u-list-item v-for="(item, index) in numList" :key="item.materialCode" style="margin-bottom: 8px">
						<view style="width: 100%;">
							<text>物料号: {{ item.materialCode || '' }}</text>
							<text style="margin-left: 20%;">数量: {{ item.quantity || '' }}</text>
						</view>
					</u-list-item>
					<u-list-item v-for="(item, index) in umodelList" :key="item.id" style="margin-bottom: 8px" >
						<view class="card">
							<view class="flex record-title">
								<text class="label">标签条码:{{ item.outCode || '' }}</text>
								<!-- <text class="value"></text> -->
							</view>
							<view class="flex flex-col justify-between flex-1 h-full record-content-body" style="padding-bottom: 0px">
								<view class="record-content">
									<view class="record-item">
										<text>供应商: {{ item.partnerName || '' }}</text>
									</view>
								</view>
							</view>
							<view class="flex flex-col justify-between flex-1 h-full record-content-body" style="padding-bottom: 0px">
								<view class="record-content">
									<view class="record-item">
										<text>物料号: {{ item.materialCode || '' }}</text>
									</view>
								</view>
							</view>
							<view class="flex flex-col justify-between flex-1 h-full record-content-body" style="padding-bottom: 0px">
								<view class="record-content">
									<view class="record-item">
										<text>批次: {{ item.stockBatch || '' }}</text>
										<text>数量: {{ item.quantity || '' }}</text>
									</view>
								</view>
							</view>
							<view class="flex flex-col justify-between flex-1 h-full record-content-body" style="padding-bottom: 0px">
								<view class="record-content">
									<view class="record-item">
										<text>仓库: {{ item.warehouseName || '' }}</text>
										<text>仓位: {{ item.binName || '' }}</text>
									</view>
								</view>
							</view>
						</view>
					</u-list-item>
				</u-list>
			</view>
		</view>
	</view>
	<!-- <u-picker
		:show="showBinPicker"
		:columns="columnsBin"
		title="仓位"
		keyName="binCode"
		immediateChange
		@cancel="showBinPicker = false"
		@confirm="BinSelect"
	></u-picker> -->
	<u-back-top :scroll-top="scrollTop" bottom="55" mode="squery"></u-back-top>
</template>

<script lang="ts" setup>
import dayjs from 'dayjs';
import { ref, reactive, onMounted, computed, toRaw, watch } from 'vue';
import { onPageScroll, onLoad, onReachBottom, onShow } from '@dcloudio/uni-app';
import ScanBar from '@/components/scan-bar/index.vue';
import { http } from '@/utils/http';
import { CommonValue, PageResult } from '@/types/type';
import { useDictionaryStore } from '@/stores/useDictionaryStore';
//import { getMdmBininfosApi } from '@/api/common';
import { useWmsStore } from '@/stores/useWmsStore';

// 获取安全距离高度
const { safeAreaInsets } = uni.getSystemInfoSync();

// 监听页面到顶部距离
const scrollTop = ref(0);
onPageScroll((e) => {
	scrollTop.value = e.scrollTop;
});

// 待完成数据
const numList = ref([]);
const current = ref(0);
const umodelList = ref([]);
const totalPage = ref(0);
const total = ref(0);

const scrolltolower = () => {
	totalPage.value > current.value;
};
// 触底监听
onReachBottom(() => {
	scrolltolower();
});

// onLoad(() => {
// 	getInboundtype();
// });

function resetFields() {
	scanBarRef1.value.reset();
	scanBarRef2.value.reset();
	scanBarRef3.value.reset();

	current.value = 0;
	umodelList.value = [];

	umodel.outCode = '';
	umodel.id = '';
	umodel.extenalCode = '';
	umodel.binId = '';
	umodel.binCode = '';
	umodel.binName = '';
	umodel.warehouseId = '';
	umodel.warehouseCode = '';
	umodel.warehouseName = '';
	umodel.storageSectionId = '';
	umodel.storageSectionCode = '';
	umodel.storageSectionName = '';
	umodel.shelfId = '';
	umodel.shelfCode = '';
	umodel.shelfName = '';
	umodel.materialCode = '';
	umodel.poSa = '';
	umodel.sd = '';
	umodel.serial = '';
	umodel.stockBatch = '';
	umodel.partnerCode = '';
	umodel.quantity = '';
	umodel.storeId= '';
	umodel.addType = 2;
	umodel.rfId = '';
	umodel.quantityUnit = '';
}
// 表单数据定义
let umodel: any = reactive({
	// 项目
	id:'',
	code: '',
	binId: '',
	binCode: '',
	binName: '',
	warehouseId: '',
	warehouseCode: '',
	warehouseName: '',
	storageSectionId: '',
	storageSectionCode: '',
	storageSectionName: '',
	shelfId: '',
	shelfCode: '',
	shelfName: '',
	materialId: '',
	materialCode: '',
	materialName: '',
	poSa: '',
	sd: '',
	serial: '',
	stockBatch: '',
	partnerId: '',
	partnerCode: '',
	partnerName: '',
	quantity: '',
	addType: 2,
	rfId: '',
	quantityUnit: '',
	outCode: '',
	storeId: '',
	extenalCode: '',
	inboundTypeId: '',
	inboundTypeCode: '',
	inboundTypeName: ''
});


// -----------------提交----------------------------------------------------
const postLoading = ref(false);
const submit = async () => {
	console.log('submit', umodelList.value);
	
	for (let i = 0; i < umodelList.value.length; i++) {	
		if(!umodelList.value[i].quantity){
			uni.showToast({
				title: '第' + (i+1) + '条未输入数量！\n请点击输入数量！',
				icon: 'error'
			});
			return;					
		}
	}
	postLoading.value = true;
	await http({
		method: 'POST',
		url: '/wms/srmstore/saveBatch',
		data: umodelList.value
	})
		.then((res) => {
			console.log('then', res);
			current.value = 0;
			umodelList.value = [];
			umodel.binId = '';
			umodel.id = '';
			umodel.binCode = '';
			umodel.binName = '';
			umodel.warehouseId = '';
			umodel.warehouseCode = '';
			umodel.warehouseName = '';
			umodel.storageSectionId = '';
			umodel.storageSectionCode = '';
			umodel.storageSectionName = '';
			umodel.shelfId = '';
			umodel.shelfCode = '';
			umodel.shelfName = '';
			umodel.scoreId = '';
			uni.showToast({
				title: `入库成功`
			});			
			postLoading.value = false;	
			setTimeout(() => {
				uni.navigateBack();
			}, 1000);	
		})
		.catch(() => {
			console.log('catch', umodelList.value);
		})
		.finally(() => {
			console.log('finally', umodelList.value);	
		});
};
const submit2 = async () => {
	postLoading.value = true;
	
	for (let i = 0; i < umodelList.value.length; i++) {	
		if(!umodelList.value[i].quantity){
			uni.showToast({
				title: '第' + (i+1) + '条未输入数量！\n请点击输入数量！',
				icon: 'error'
			});
			return;					
		}
	}
	await http({
		method: 'POST',
		url: '/wms/srmstore/saveBatch',
		data: umodelList.value
	})
		.then((res) => {
			console.log('then', res);
			current.value = 0;
			umodelList.value = [];
			umodel.binId = '';
			umodel.binCode = '';
			umodel.binName = '';
			umodel.warehouseId = '';
			umodel.warehouseCode = '';
			umodel.warehouseName = '';
			umodel.storageSectionId = '';
			umodel.storageSectionCode = '';
			umodel.storageSectionName = '';
			umodel.shelfId = '';
			umodel.shelfCode = '';
			umodel.shelfName = '';
			umodel.scoreId = '';
			uni.showToast({
				title: `入库成功`
			});			
			postLoading.value = false;	
		})
		.catch(() => {
			console.log('catch', umodelList.value);
		})
		.finally(() => {
			console.log('finally', umodelList.value);	
			setTimeout(() => {
				resetFields();
			}, 1000);	
		});
};
// -----------------输入数量----------------------------------------------------
function setQuantity(index){
	const regex = /^\-?\d+(\.\d+)?$/;
	uni.showModal({
		title:"数量",
		// content:"确认要删除吗？",
		showCancel:true,
		cancelColor:"#00bfff",
		confirmColor:"#dd524d",
		editable:true,
		placeholderText:"请输入数量",
			success:function(res){
			if(res.confirm && regex.test(res.content)){
				umodelList.value[index].quantity = res.content;
			}else if(res.confirm){
				uni.showToast({
					title: '必须输入数字！\n请重新点击输入！',
					icon: 'error'
				});
			}else if(res.cancel){
				uni.showToast({
					title: '取消操作',
					icon: 'error'
				});
			}
		}
	})
}
// -----------------RFID----------------------------------------------------
const scanBarRef3 = ref();
let rfidLoading = false;//网络请求监控
async function scanRFID(result: string) {
	console.log('scanRFID', result);
	if (result) {
		if(rfidLoading){
			uni.showToast({
				title: '网络请求未响应',
				icon: 'error'
			});
			return;		
		}
		if(!umodelList.value || umodelList.value.length == 0){
			uni.showToast({
				title: '请先扫描标签条码',
				icon: 'error'
			});
			scanBarRef3.value.reset();
			scanBarRef1.value.reset();
			rfidLoading = false;
			return;		
		}
		rfidLoading = true;
		await http({
			url: `/wms/mdmrfid/getMdmRfidDTO`,
			method: 'POST',
			data:{"rfidCode":result}
		}).then((res) => {
			let data = res.data;
			console.log('mdmrfid|getMdmRfidDTO', data);
			if(res.code != 200){
				uni.showToast({
					title: data,
					icon: 'error'
				});				
				scanBarRef3.value.reset();
				rfidLoading = false;
				return;				
			}else 
			if(data && data.length == 0){
				uni.showToast({
					title: 'RFID标签未维护',
					icon: 'error'
				});				
				scanBarRef3.value.reset();
				rfidLoading = false;
				return;
			}else{				
				umodel.rfId = result;
				if(umodelList.value && umodelList.value.length > 0){
					umodelList.value[0].rfId = result;			
				}		
			}
		})
		.catch(() => {
			console.log('catch', umodelList.value);
		})
		.finally(() => {
			console.log('finally', umodelList.value);	
			scanBarRef3.value.reset();
			rfidLoading = false;
		});
	}
}
// -----------------条码----------------------------------------------------
const scanBarRef1 = ref();
let barcodeLoading = false;
async function barcodeParsing(result: string) {
	if(barcodeLoading){
		uni.showToast({
			title: '网络请求未响应',
			icon: 'error'
		});
		return;		
	}
	barcodeLoading = true;
	console.log('barcodeParsing', result);
	if (result) {
		for (let i = 0; i < umodelList.value.length; i++) {			
			if (umodelList.value[i].outCode == result) {
				uni.showToast({
					title: '不可重复扫描',
					icon: 'error'
				});
				scanBarRef1.value.reset();
				barcodeLoading = false;
				return;
			}
		}

	await http({
		method: 'POST',
		url: '/wms/srmstore/barcodeVerify',
		data: {
	'inboundTypeCode': "1",'details':[{'outCode':result}]}
	})
		.then((res) => {
			let data = res.data;
			// const regex = /^\-?\d+(\.\d+)?$/;
			// uni.showModal({
			// 	title:"数量",
			// 	// content:"确认要删除吗？",
			// 	showCancel:true,
			// 	cancelColor:"#00bfff",
			// 	confirmColor:"#dd524d",
			// 	editable:true,
			// 	placeholderText:"请输入数量",
			// 		success:function(res){
			// 			if(res.confirm && regex.test(res.content)){
						console.log('srmasn|barcodeParsing', data);
						umodel.outCode = result;
						umodel.extenalCode = result;
						umodel.materialId = data.materialId;
						umodel.materialCode = data.materialCode;
						umodel.materialName = data.materialName;
						umodel.poSa = data.poSa;
						umodel.sd = data.sd;
						umodel.serial = data.serial;
						umodel.stockBatch = data.batch;
						umodel.partnerId = data.partnerId;
						umodel.partnerCode = data.partnerCode;
						umodel.partnerName = data.partnerName;
						umodel.quantity = data.quantity;
						umodel.quantityUnit = data.unitName;
						umodel.isRfid = data.isRfid;		
						umodel.storeId = data.storeId;	
						umodel.asnId = data.asnId;		
						if(data.inboundTypeId){			
							umodel.inboundTypeId = data.inboundTypeId;
							umodel.inboundTypeCode = data.inboundTypeCode;
							umodel.inboundTypeName = data.inboundTypeName;
						}
						if (data.binId) {
							umodel.binId = data.binId;
							umodel.binCode = data.binCode;
							umodel.barcode = data.barcode;
							umodel.binName = data.binName;
							umodel.warehouseId = data.warehouseId;
							umodel.warehouseCode = data.warehouseCode;
							umodel.warehouseName = data.warehouseName;
							umodel.storageSectionId = data.storageSectionId;
							umodel.storageSectionCode = data.storageSectionCode;
							umodel.storageSectionName = data?.storageSectionName;
							umodel.shelfId = data.shelfId;
							umodel.shelfCode = data.shelfCode;
							umodel.shelfName = data?.shelfName;
							scanBarRef2.value?.setScanCode(data.barcode);
						}
						let umodelNewList = [];
						umodelNewList.push(JSON.parse(JSON.stringify(umodel)));
						for (let i = 0; i < umodelList.value.length; i++) {
							umodelNewList.push(JSON.parse(JSON.stringify(umodelList.value[i])));
						}
						
						umodelList.value = umodelNewList;
						console.log('barcodeParsing|end', umodelList.value);	


						numList.value = [];
						for (let i = 0; i < umodelList.value.length; i++) {		
							let numboolean = false;
							for (let j = 0; j < numList.value.length; j++) {
								if(umodelList.value[i].materialCode == numList.value[j].materialCode){
									numboolean = true;
									numList.value[j].quantity = Number(umodelList.value[i].quantity)+Number(numList.value[j].quantity) ;
									
									if(numList.value[j].quantity % 1 != 0){
										numList.value[j].quantity.toFixed(3)
									}
								}
							}
							console.log('numboolean:', numboolean);
							if(!numboolean){
								numList.value.push({"materialCode":umodelList.value[i].materialCode , "quantity":umodelList.value[i].quantity});				
							}
						}			
				// 	}else if(res.confirm){
				// 		uni.showToast({
				// 			title: '必须输入数字！\n请重新扫描！',
				// 			icon: 'error'
				// 		});
				// 	}else if(res.cancel){
				// 		uni.showToast({
				// 			title: '取消操作',
				// 			icon: 'error'
				// 		});
				// 	}
				// }
			//})
		
		})
		.catch(() => {
			console.log('catch', umodelList.value);
		})
		.finally(() => {
			console.log('finally', umodelList.value);	
			scanBarRef1.value.reset();
			barcodeLoading = false;
		});
	}
}
//多选使用
async function barcodeParsing2(result: string) {
	barcodeLoading = true;
	console.log('barcodeParsing', result);
	if (result) {
		for (let i = 0; i < umodelList.value.length; i++) {
			if (umodelList.value[i].outCode == result) {
				uni.showToast({
					title: '不可重复扫描',
					icon: 'error'
				});
				scanBarRef1.value.reset();
				barcodeLoading = false;
				return;
			}
		}

		
		await http({
			method: 'POST',
			url: '/wms/srmstore/barcodeVerify',
			data: {
	'inboundTypeCode': "1",'details':[{'outCode':result}]}
		}).then((res) => {
			let data = res.data;
			console.log('srmasn|barcodeParsing', data);
			umodel.outCode = result;
			umodel.extenalCode = result;
			umodel.materialId = data.materialId;
			umodel.materialCode = data.materialCode;
			umodel.materialName = data.materialName;
			umodel.poSa = data.poSa;
			umodel.sd = data.sd;
			umodel.serial = data.serial;
			umodel.stockBatch = data.batch;
			umodel.partnerId = data.partnerId;
			umodel.partnerCode = data.partnerCode;
			umodel.partnerName = data.partnerName;
			umodel.quantity = data.quantity;
			umodel.quantityUnit = data.unitName;
			umodel.isRfid = data.isRfid;		
			umodel.storeId = data.storeId;	
			umodel.asnId = data.asnId;	
			if(data.inboundTypeId){			
				umodel.inboundTypeId = data.inboundTypeId;
				umodel.inboundTypeCode = data.inboundTypeCode;
				umodel.inboundTypeName = data.inboundTypeName;
			}
			if (data.binId) {
				umodel.binId = data.binId;
				umodel.binCode = data.binCode;
				umodel.barcode = data.barcode;
				umodel.binName = data.binName;
				umodel.warehouseId = data.warehouseId;
				umodel.warehouseCode = data.warehouseCode;
				umodel.warehouseName = data.warehouseName;
				umodel.storageSectionId = data.storageSectionId;
				umodel.storageSectionCode = data.storageSectionCode;
				umodel.storageSectionName = data?.storageSectionName;
				umodel.shelfId = data.shelfId;
				umodel.shelfCode = data.shelfCode;
				umodel.shelfName = data?.shelfName;
				scanBarRef2.value?.setScanCode(data.barcode);
			}
			let umodelNewList = [];
			umodelNewList.push(JSON.parse(JSON.stringify(umodel)));
			for (let i = 0; i < umodelList.value.length; i++) {
				umodelNewList.push(JSON.parse(JSON.stringify(umodelList.value[i])));
			}
			
			umodelList.value = umodelNewList;
			console.log('barcodeParsing|end', umodelList.value);	


			numList.value = [];
			for (let i = 0; i < umodelList.value.length; i++) {		
				let numboolean = false;
				for (let j = 0; j < numList.value.length; j++) {
					if(umodelList.value[i].materialCode == numList.value[j].materialCode){
						numboolean = true;
						numList.value[j].quantity = Number(umodelList.value[i].quantity)+Number(numList.value[j].quantity) ;
						
						if(numList.value[j].quantity % 1 != 0){
							numList.value[j].quantity.toFixed(3)
						}
					}
				}
				console.log('numboolean:', numboolean);
				if(!numboolean){
					numList.value.push({"materialCode":umodelList.value[i].materialCode , "quantity":umodelList.value[i].quantity});				
				}
			}			
		
		})
		.catch(() => {
			console.log('catch', umodelList.value);
		})
		.finally(() => {
			console.log('finally', umodelList.value);	
			scanBarRef1.value.reset();
			barcodeLoading = false;
		});
	}
}

// -----------------仓位1----------------------------------------------------
const scanBarRef2 = ref();
async function scanBin(result: string) {
	console.log('scanBin', result);
	if (result) {
		const { data } = await http({
			url: `/wms/wmsbin/getByBarcode/${result}`,
			method: 'GET'
		});
		console.log('scanBin', data);
		umodel.binName = data.binName;
		umodel.binCode = data.binCode;
		umodel.binId = data.id;
		umodel.warehouseId = data.warehouseId;
		umodel.warehouseCode = data.warehouseCode;
		umodel.warehouseName = data.warehouseName;
		umodel.storageSectionId = data.storageSectionId;
		umodel.storageSectionCode = data.storageSectionCode;
		umodel.storageSectionName = data.storageSectionName;
		umodel.shelfId = data.shelfId;
		umodel.shelfCode = data.shelfCode;
		umodel.shelfName = data.shelfName;

		for(let i = 0 ; i < umodelList.value.length ; i ++){
			umodelList.value[i].warehouseId = data.warehouseId;
			umodelList.value[i].warehouseCode = data.warehouseCode;
			umodelList.value[i].warehouseName = data.warehouseName;
			umodelList.value[i].storageSectionId = data.storageSectionId;
			umodelList.value[i].storageSectionCode = data.storageSectionCode;
			umodelList.value[i].storageSectionName = data.storageSectionName;
			umodelList.value[i].shelfId = data.shelfId;
			umodelList.value[i].shelfCode = data.shelfCode;
			umodelList.value[i].shelfName = data.shelfName;
			umodelList.value[i].binId = data.id;
			umodelList.value[i].binName = data.binName;
			umodelList.value[i].binCode = data.binCode;
		}
		
		
		// if(umodelList.value.length > 0){
		// 	umodelList.value[0].warehouseId = data.warehouseId;
		// 	umodelList.value[0].warehouseCode = data.warehouseCode;
		// 	umodelList.value[0].warehouseName = data.warehouseName;
		// 	umodelList.value[0].storageSectionId = data.storageSectionId;
		// 	umodelList.value[0].storageSectionCode = data.storageSectionCode;
		// 	umodelList.value[0].storageSectionName = data.storageSectionName;
		// 	umodelList.value[0].shelfId = data.shelfId;
		// 	umodelList.value[0].shelfCode = data.shelfCode;
		// 	umodelList.value[0].shelfName = data.shelfName;
		// 	umodelList.value[0].binId = data.id;
		// 	umodelList.value[0].binName = data.binName;
		// 	umodelList.value[0].binCode = data.binCode;				
		// }
	}
}

// -----------------仓位2----------------------------------------------------
function binScan() {
	uni.navigateTo({
		url: `/pages/wms/procurementstore/binSelect`
	});
}
// 选择仓位信息
const deviceList = computed(() => JSON.parse(useWmsStore().deviceList));
console.log("qqq",deviceList.value)
console.log("qqq2",umodelList)
//console.log("1111",deviceList.value)
// 监控仓位选择id
watch(
	() => deviceList,
	async (newVal) => {
		if (newVal.value[0]?.id && newVal.value[0]?.binCode) {
			umodel.binId = newVal.value[0]?.id;
			umodel.binCode = newVal.value[0]?.binCode;
			umodel.binName = newVal.value[0]?.binName;
			umodel.warehouseId = newVal.value[0]?.warehouseId;
			umodel.warehouseCode = newVal.value[0]?.warehouseCode;
			umodel.warehouseName = newVal.value[0]?.warehouseName;
			umodel.storageSectionId = newVal.value[0]?.storageSectionId;
			umodel.storageSectionCode = newVal.value[0]?.storageSectionCode;
			umodel.storageSectionName = newVal.value[0]?.storageSectionName;
			umodel.shelfId = newVal.value[0]?.shelfId;
			umodel.shelfCode = newVal.value[0]?.shelfCode;
			umodel.shelfName = newVal.value[0]?.shelfName;
			if(newVal.value[0]?.barcode){
				scanBarRef2.value?.setScanCode(newVal.value[0]?.barcode);				
			}

			for(let i = 0 ; i < umodelList.value.length ; i ++){
				umodelList.value[i].warehouseId = newVal.value[0]?.warehouseId;
				umodelList.value[i].warehouseCode = newVal.value[0]?.warehouseCode;
				umodelList.value[i].warehouseName = newVal.value[0]?.warehouseName;
				umodelList.value[i].storageSectionId = newVal.value[0]?.storageSectionId;
				umodelList.value[i].storageSectionCode = newVal.value[0]?.storageSectionCode;
				umodelList.value[i].storageSectionName = newVal.value[0]?.storageSectionName;
				umodelList.value[i].shelfId = newVal.value[0]?.shelfId;
				umodelList.value[i].shelfCode = newVal.value[0]?.shelfCode;
				umodelList.value[i].shelfName = newVal.value[0]?.shelfName;
				umodelList.value[i].binId = newVal.value[0]?.id;
				umodelList.value[i].binName = newVal.value[0]?.binName;
				umodelList.value[i].binCode = newVal.value[0]?.binCode;
			}
			
			// if(umodelList.value.length > 0){
			// 	umodelList.value[0].warehouseId = newVal.value[0]?.warehouseId;
			// 	umodelList.value[0].warehouseCode = newVal.value[0]?.warehouseCode;
			// 	umodelList.value[0].warehouseName = newVal.value[0]?.warehouseName;
			// 	umodelList.value[0].storageSectionId = newVal.value[0]?.storageSectionId;
			// 	umodelList.value[0].storageSectionCode = newVal.value[0]?.storageSectionCode;
			// 	umodelList.value[0].storageSectionName = newVal.value[0]?.storageSectionName;
			// 	umodelList.value[0].shelfId = newVal.value[0]?.shelfId;
			// 	umodelList.value[0].shelfCode = newVal.value[0]?.shelfCode;
			// 	umodelList.value[0].shelfName = newVal.value[0]?.shelfName;
			// 	umodelList.value[0].binId = newVal.value[0]?.id;
			// 	umodelList.value[0].binName = newVal.value[0]?.binName;
			// 	umodelList.value[0].binCode = newVal.value[0]?.binCode;				
			// }
		}
		if (newVal.value[0]?.selectList) {
			// setTimeout(() => {
			// 	barcodeParsing(newVal.value[0]?.outCode);
			// }, 500);
			// scanBarRef1.value?.setScanCode(newVal.value[0]?.outCode);
			for(let i = 0; i < newVal.value[0]?.selectList.length; i++){
				setTimeout(() => {
					barcodeParsing2(newVal.value[0]?.selectList[i].barCode);
				}, 100*(i+1));
				umodel.inboundTypeId = newVal.value[0]?.selectList[i].inboundTypeId;
				umodel.inboundTypeCode = newVal.value[0]?.selectList[i].inboundTypeCode;
				umodel.inboundTypeName = newVal.value[0]?.selectList[i].inboundTypeName;

			}			
		}
		setTimeout(() => {
			useWmsStore().setDeviceList();
		}, 1000);
	},
	{
		deep: true,
		immediate: true
	}
);
// -----------------返回按钮----------------------------------------------------
const cancelBtn = () => {
	uni.navigateBack();
};
</script>

<style lang="scss" scoped>
.baseForm {
	padding: $uni-page-padding;
	background-color: #fbfbff;
	height: 95vh;
	.u-form {
		:deep(.u-form-item__body) {
			padding: 5px 0;
		}
	}
	:deep(.uni-date__x-input) {
		padding-left: 2px;
		font-size: 13px;
	}
	:deep(.uni-date-x .icon-calendar) {
		font-size: 20px;
		padding-left: 8px;
	}
	.u-line {
		padding: 8px 0;
	}
	.submit_btn {
		position: fixed;
		bottom: 0;
		height: 42px;
		border-radius: 10px;
		margin: 10px 0px;
		width: calc(100% - 30px);
		font-size: 18px;
		:deep(.u-button__text) {
			font-size: 16px !important;
			font-weight: bold;
		}
	}
	.inputHeight {
		height: 20px;
	}
	.search-btn {
		height: 36px;
		border-radius: 6px;
	}

	.delete {
		color: #fa3534 !important;
	}
	.edit {
		color: #0076ff !important;
		display: inline-block;
		margin-right: 15px;
	}
}

.card {
	background-color: #fff;
	border-radius: 8px;
	padding: 5px 12px;
	transition: all 300ms ease;
	box-shadow: 0 2px 6px rgba(3, 121, 255, 0.05);
	border: 1px solid silver;

	.record-title {
		display: flex;
		justify-content: space-between;
		margin: 5px 0 3px 0;
		// color: $primary-color;
		color: #333 !important;
		word-break: break-all;

		uni-text:nth-child(1) {
			font-weight: bold;
			font-size: 16px;
		}

		uni-text:nth-child(2) {
			// font-weight: bold;
			font-size: 16px;
			min-width: 60px;
			text-align: right;
		}
	}
	.record-item {
		margin: 3px 0 !important;
		// color: #777 !important;
		// color: $primary-color;
		color: #333 !important;
		display: flex;
		align-items: center;
		font-size: 14px;

		> :first-child {
			min-width: 63px;
		}

		:deep(.u-tag__text--mini) {
			font-size: 13px;
			padding: 1px 3px 0;
		}
	}
}
:deep(.line1) {
	display: flex !important;
	span:nth-last-child(1) {
		display: inline-block !important;
		white-space: nowrap !important;
		text-overflow: ellipsis !important;
		word-break: break-word !important;
		overflow: hidden !important;
	}
}
:deep(.uicon-empty-list) {
	margin-top: 10px;
	font-size: 50px !important;
	line-height: 50px !important;
}
</style>
